package com.base.cn.platform.os.service.course.count;

import com.base.cn.platform.os.common.mybatis.BaseBiz;
import com.base.cn.platform.os.common.utils.ObjectUtils;
import com.base.cn.platform.os.dao.course.count.CourseSubjectPlayNumDao;
import com.base.cn.platform.os.entity.course.count.CourseSubjectPlayNum;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * 专业播放统计
 *
 * @author s.li
 * @date 2019/04/15
 */
@Service
public class CourseSubjectPlayNumBiz extends BaseBiz<CourseSubjectPlayNum, CourseSubjectPlayNumDao> {

    /**
     * 添加专业播放量
     * @param subjectIds
     */
    @Async
    public void createCourseSubjectPlayNum(String subjectIds) {
        CourseSubjectPlayNum courseSubjectPlayNum = this.findOne(" subjectIds ='"+subjectIds+"'",null);
        if(!ObjectUtils.isNotEmpty(courseSubjectPlayNum)){
            courseSubjectPlayNum = new CourseSubjectPlayNum();
            courseSubjectPlayNum.setSubjectIds(subjectIds);
            courseSubjectPlayNum.setPlayCount(1);
            this.save(courseSubjectPlayNum);
        }else{
            courseSubjectPlayNum.setPlayCount(courseSubjectPlayNum.getPlayCount().intValue() +1);
            this.updateById(courseSubjectPlayNum,null);
        }
    }
}
